package textprocessing.nlpanalysis.constituent;

import edu.stanford.nlp.trees.Tree;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by julianzliu on 4/19/2017.
 */

/*
一个Context由一组词汇构成.
这些Token是树中的叶子节点
 */
public class ContextItem {

    private List<Tree> tokens;

    public ContextItem(){
        this.tokens = new ArrayList<>();
    }


    public List<Tree> getTokens(){
        return this.tokens;
    }

    public void addTokenLast(Tree token){
        this.tokens.add(token);
    }

    public void addTokenFirst(Tree token){
        this.tokens.add(0,token);
    }


    public void copy(ContextItem item){
        //this.tokens = Arrays.copyOf(item.tokens, item.tokens.size());
        this.tokens = new ArrayList<>(item.tokens);
    }

    public void extendLast(ContextItem item){
        this.tokens.addAll( item.tokens );
    }

    public void extendFirst(ContextItem item){
        this.tokens.addAll(0, item.tokens );
    }

    @Override
    public String toString(){
        String context = "";
        for(Tree token:tokens){
            context += token.label();
            context += " ";
        }
        return context;
    }
}
